<?php

namespace common\models\db\tables;

use Yii;

/**
 * This is the model class for table "{{%tag}}".
 *
 * @property string $id
 * @property string $name
 * @property int $frequency 频率
 *
 * @property DocuTag[] $docuTags
 * @property Docu[] $docus
 */
class Tag extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%tag}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['name', 'frequency'], 'required'],
            [['frequency'], 'integer'],
            [['name'], 'string', 'max' => 191],
            [['name'], 'unique'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'name' => Yii::t('app', 'Name'),
            'frequency' => Yii::t('app', '频率'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocuTags()
    {
        return $this->hasMany(DocuTag::className(), ['tag_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getDocus()
    {
        return $this->hasMany(Docu::className(), ['id' => 'docu_id'])->viaTable('{{%docu_tag}}', ['tag_id' => 'id']);
    }
}
